<template>
	<view class="wrapper">
		<daya-footer-navbar menu_type="shangjia" />
		<view class="head" :style="{paddingTop: top + 44 + 'px'}">
			<view class="left">
				<image class="headimage" mode="aspectFill" :src="storeinfo.store.logo"></image>
				<view class="desc">
					<view class="name">{{ storeinfo.store.name }}</view>
					<view class="time">到期时间：{{ storeinfo.store.rzdq_time }}</view>
				</view>
			</view>
			<view class="sycs">
				<!-- <view>订单提醒可用</view> -->
				<view class="sycsv1">
					<image class="sycsimage" src="/static/ymq_canyino2o/xx.png"></image>
					<!-- <view>{{ sycs }}次</view> -->
				</view>
			</view>
		</view>
		<view class="content">
			<view class="weui-cell">
				<view class="weui-cell__hd">
					<image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/seller/zdjd.png"></image>
				</view>
				<view class="weui-cell__bd">
					自动接单
					<!-- <text style="color: #999; font-size: 22rpx; margin-left: 20rpx">({{ jdkgtext }})</text> -->
				</view>
				<view class="weui-cell__ft">
					<switch @change="jdswitchChange" :checked="jdkg"></switch>
				</view>
			</view>
			<view class="weui-cell">
				<view class="weui-cell__hd">
					<image src="https://yunkeososyunchuc.bc8t.cn/ymq_canyino2o/static/seller/five.png"></image>
				</view>
				<view class="weui-cell__bd">
					语音播报
					<!-- <text style="color: #999; font-size: 22rpx; margin-left: 20rpx">({{ yykgtext }},自动接单关闭后有效)</text> -->
				</view>
				<view class="weui-cell__ft">
					<switch @change="yyswitchChange" :checked="yykg"></switch>
				</view>
			</view>
		</view>
		<view class="wrappers">
			<navigator class="item" url="wytx">
				<view class="weui-cell__hd">
					<image style="margin-right: 0; margin-bottom: 20rpx" src="/static/ymq_canyino2o/wytx.png"></image>
				</view>
				<view>我要提现</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>
			<navigator class="item" url="sjzl">
				<view class="weui-cell__hd">
					<image style="margin-right: 0; margin-bottom: 20rpx" src="/static/ymq_canyino2o/mdxx.png"></image>
				</view>
				<view>门店信息</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>
			<navigator class="item" url="dpsz?szname=1">
				<view class="weui-cell__hd">
					<image style="margin-right: 0; margin-bottom: 20rpx" src="/static/ymq_canyino2o/dysz.png"></image>
				</view>
				<view>打印设置</view>
				<!-- <picker @change="bindCountryChange" :range="countries" style="flex: 2" :value="countryIndex">
					<view class="weui-cell__ft weui-cell__ft_in-access"></view>
				</picker> -->
			</navigator>
			<navigator class="item" url="dpsz?szname=2">
				<view class="weui-cell__hd">
					<image style="margin-right: 0; margin-bottom: 20rpx" src="/static/ymq_canyino2o/yysj.png"></image>
				</view>
				<view>营业时间</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>


			<navigator class="item" url="/ymq_canyino2o/pages/sjzx/sjtj/sjtj">
				<view class="weui-cell__hd">
					<image style="margin-right: 0; margin-bottom: 20rpx" src="/static/ymq_canyino2o/sjtj.png"></image>
				</view>
				<view>数据统计</view>
				<!-- <view class="weui-cell__ft weui-cell__ft_in-access"></view> -->
			</navigator>


		</view>
		<form @reset="formReset" @submit="cartaddformSubmit" :reportSubmit="true"
			v-if="user_id == storeinfo.store.admin_id">
			<view class="weui-btn-area">
				<button class="weui-btn" formType="submit"  type="primary">
					下单提醒按钮
				</button>
			</view>
		</form>
		<view class="weui-btn-area">
			<button @tap="tcdl" class="weui-btn"  type="primary">
				退出登录
			</button>
		</view>
	</view>
</template>

<script>
	import {
		mutations as uniIdMutations
	} from '@/uni_modules/uni-id-pages/common/store.js'


	import cardlist from '@/ymq_canyino2o/dist/cardlist/index'
	import gettel from '@/ymq_canyino2o/dist/gettel/index'
	var app = getApp()
	export default {
		components: {
			cardlist,
			gettel
		},
		data() {
			return {
				yykgtext: '语音播报已关闭',

				storeinfo: {
					store: {
						logo: '',
						name: '',
						rzdq_time: '',
						admin_id: ''
					}
				},

				user_id: '',
				jdkg: false,
				jdkgtext: '',
				yykg: false,
				sycs: '',


				color: '',
				countries: [],
				countryIndex: 0,
				top: 0
			}
		},
		onLoad: function(t) {
			this.top = uni.getSystemInfoSync().statusBarHeight
			var that = this
			var e = uni.getStorageSync('sjdsjid')
			var o = uni.getStorageSync('users').id
			console.log(e, o)
			app.globalData.setNavigationBarColor(this)
			app.globalData.sjdappPageOnLoad(this)
			app.globalData.util.request({
				url: 'entry/wxapp/StoreInfo',
				cachetime: '0',
				data: {
					store_id: e
				},
				success: function(t) {
					console.log('商家详情', t)
					that.setData({
						storeinfo: t.data,
						user_id: o
					})
					that.reLoad()
					if ('1' == t.data.storeset.is_jd) {
						that.setData({
							jdkg: true,
							jdkgtext: '自动接单已开启'
						})
					}
					if ('2' == t.data.storeset.is_jd) {
						that.setData({
							jdkg: false,
							jdkgtext: '自动接单已关闭'
						})
					}
				}
			})
			if (uni.getStorageSync('yybb')) {
				that.setData({
					yykg: true,
					yykgtext: '语音播报已开启'
				})
			}
		},
		onReady: function() {},
		onShow: function() {},
		onHide: function() {},
		onUnload: function() {},
		onPullDownRefresh: function() {},
		methods: {
			cartaddformSubmit: function(t) {
				console.log('formid', t.detail.formId)
				var that = this
				var e = this.storeinfo.store.admin_id
				app.globalData.util.request({
					url: 'entry/wxapp/AddFormId',
					cachetime: '0',
					data: {
						user_id: e,
						form_id: t.detail.formId
					},
					success: function(t) {
						console.log(t.data)
						that.reLoad()
					}
				})
			},

			tcdl: function() {


				//退出uni-id身份
				uniIdMutations.logout()
				uni.removeStorageSync('store_is_login')


				uni.removeStorageSync('sjdsjid')
				uni.reLaunch({
					url: '/ymq_canyino2o/pages/my2/index?is_show_login=1',
					fail: (e) => {
						uni.reLaunch({
							url: '/ymq_canyino2o/pages/my2/index?is_show_login=1',
						})
					}
				})
			},

			jdswitchChange: function(a) {
				var that = this
				var t = uni.getStorageSync('sjdsjid')
				console.log(t)
				console.log('jdswitchChange 发生 change 事件，携带值为', a.detail.value)
				if (a.detail.value) {
					var o = 1
				} else {
					o = 2
				}
				console.log(o)
				uni.showLoading({
					title: '提交中',
					mask: true
				})
				app.globalData.util.request({
					url: 'entry/wxapp/UpStore',
					cachetime: '0',
					data: {
						store_id: t,
						is_jd: o
					},
					success: function(t) {
						console.log(t.data)
						if ('1' == t.data) {
							uni.showToast({
								title: '设置成功',
								icon: 'success',
								duration: 1000
							})
							if (a.detail.value) {
								that.setData({
									jdkgtext: '自动接单已开启'
								})
							} else {
								that.setData({
									jdkgtext: '自动接单已关闭'
								})
							}
						} else {
							if ('2' == t.data) {
								uni.showToast({
									title: '请修改后提交',
									icon: 'loading',
									duration: 1000
								})
							} else {
								uni.showToast({
									title: '请重试',
									icon: 'loading',
									duration: 1000
								})
							}
						}
					}
				})
			},

			yyswitchChange: function(t) {
				console.log('switch2 发生 change 事件，携带值为', t.detail.value)
				if (t.detail.value) {
					uni.setStorageSync('yybb', true)
					this.setData({
						yykg: true,
						yykgtext: '语音播报已开启'
					})
				} else {
					uni.removeStorageSync('yybb')
					this.setData({
						yykg: false,
						yykgtext: '语音播报已关闭'
					})
				}
			},

			reLoad: function() {
				var that = this
				var t = this.storeinfo.store.admin_id
				app.globalData.util.request({
					url: 'entry/wxapp/MyFormId',
					cachetime: '0',
					data: {
						admin_id: t
					},
					success: function(t) {
						console.log(t.data)
						that.setData({
							sycs: t.data
						})
					}
				})
			},

			bindCountryChange() {
				console.log('占位：函数 bindCountryChange 未声明')
			},

			formReset() {
				console.log('占位：函数 formReset 未声明')
			}
		}
	}
</script>
<style>
	@import './sjzx.css';
</style>
<style lang="scss" scoped>
	.wrapper {
		min-height: 100vh;
		background: linear-gradient(180deg, #8EC0F6, #E9F1FA, #EFEFEF, #FEFEFE);

		.head {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: calc(100% - 60rpx);
			margin: 0 auto;

			.left {
				display: flex;

				.desc {
					margin-left: 20rpx;

					.name {
						font-size: 36rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #191818;
						line-height: 44rpx;
					}

					.time {
						font-size: 22rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #FFFFFF;
						line-height: 44rpx;
					}
				}
			}
		}

		.content {
			width: calc(100% - 30rpx);
			display: flex;
			justify-content: space-between;
			margin: 50rpx auto;

			.weui-cell {
				width: 45%;
				background: #FFFFFF;
				border-radius: 10rpx;
			}
		}

		.wrappers {
			width: calc(100% - 30rpx);
			display: flex;
			justify-content: space-between;
			margin: 50rpx auto;
			background: #FFFFFF;
			border-radius: 10rpx;
			display: flex;
			flex-wrap: wrap;
			padding: 20rpx 0;
			box-sizing: border-box;
			.item {
				width: 25%;
				display: flex;
				flex-direction: column;
				align-items: center;
				margin-bottom: 30rpx;
			}
		}
		.weui-btn-area {
			margin-top: 300rpx;
			button {
				background: #369FF2;
			}
		}
	}
</style>